<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-1.10.2.min.js"></script>
</head>
<body>
<!--main-header start-->
<div class="main-header">
    <div class="w-1200 clearfix">
        <div class="header-logo fl"><a href=""><img src="images/logo.png"></a> </div>
        <!--header-person start-->
        <div class="header-person fr">
            <div id="head_login"></div>
    <script type="text/javascript">
      
      $("#head_login").load("login_common.html");
    </script>
        </div>
        <!--header-person end-->
        <!--header-nav start-->
        <div class="header-nav fr">
            <ul class="nav">
                <li><a href="/user1.html">用户列表</a> </li>
                <li class="on"><a href="/user4.html">新增用户</a> </li>
            </ul>
        </div>
        <!--header-nav end-->
    </div>
</div>
<!--main-header end-->
<!--add-container start-->
<div class="add-container w-1200">
    <div class="add-content">


        <!--add-item start-->
        <div class="add-item m15">


            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>类型：</div>
                    <div class="input-w">
                        <select id="type" name="type">
                            <option value="2">业主</option>
                            <option value="3">分管领导</option>
                            <option value="4">评审专家</option>
                            <option value="5">评审机构</option>
                            <option value="0">委托机构</option>
                            <option value="1">受理员</option>
                            <option value="6">评审专员</option>
                            <option value="7">管理员</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span><span id="boxname">姓名：</span></div>
                    <div class="input-w">
                        <input type="text" class="input" id="displayname">
                    </div>
                </div>
            </div>
            
        </div>
        <!--add-item end-->



        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>账号：</div>
                    <div class="input-w">
                        <input type="text" class="input" id="account">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>密码：</div>
                    <div class="input-w">
                        <input type="text" class="input" id="password">
                    </div>
                </div>
            </div>
        </div>





        <div class="add-item m15" id="jginfo">
           
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>信用代码证：</div>
                    <div class="input-w">
                        <input type="text" class="input" id="jgcode">
                    </div>
                </div>
            </div>

            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>负责人：</div>
                    <div class="input-w">
                        <input type="text" class="input" id="fzr">
                    </div>
                </div>
            </div>


        </div>














        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>手机号：</div>
                    <div class="input-w">
                        <input type="text" class="input" id="phone">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>身份证号：</div>
                    <div class="input-w">
                        <input type="text" class="input" id="idcard">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15" id="level">
           
            


            <div class="w50" id="level">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>评审等级：</div>
                    <div class="input-w">
                        <select id="pslevel" name="salary">
                           
                        </select>
                    </div>
                </div>
            </div>




        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item" id="com">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>工作单位：</div>
                <div class="input-w">
                    <input type="text" class="input" id="company">
                </div>
            </div>
        </div>

        <div class="add-item">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>地址</div>
                <div class="input-w">
                    <input type="text" class="input" id="address">
                </div>
            </div>
        </div>
        <input type="hidden" id="isupdate" value="0">
        <input type="hidden" id="id" value="">
        <!--add-item end-->
        <!--add-item start-->


        <div class="add-item" id="goodat">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>擅长领域（空格隔开）</div>
                <div class="input-w">
                    <textarea class="txt" rows="6" id="good"></textarea>
                </div>
            </div>
        </div>


        <div class="add-item">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>文字简介：</div>
                <div class="input-w">
                    <textarea class="txt" rows="6" id="introduce"></textarea>
                </div>
            </div>
        </div>



        <!--add-item end-->
        <!--add-bottom start-->
        <div class="add-bottom bor-none">
            <button class="login-btn" onclick="adduser()">立即提交</button>
        </div>
        <!--add-bottom end-->
    </div>
</div>
<!--add-container end-->
<script src="js/jquery.selectlist.js"></script>
<script type="text/javascript">
    // $(function(){
    //     $('select').selectlist({
    //         zIndex: 10,
    //         width: 300,
    //         height: 40
    //     });
    // })

    $("#type").change(function() {

        if($("#type").val() == 5 || $("#type").val() == 0){

            $("#boxname").html("机构名称");
           
            $("#jginfo").show();
            $("#com").hide();

           
    }else{
        
        $("#jginfo").hide();
        $("#com").show();

    }



    if($("#type").val()== 4 || $("#type").val()  == 5){

        $("#level").show();
        $("#goodat").show();
    }else{
        $("#level").hide();
        $("#goodat").hide();
    }

    




});

$("#type").trigger("change");

$.get("/api/Index/getlevels",function(res){

var levels = res.result.level;
var opt = "";
$.each(levels,function(k,v){

    opt+=`<option value=`+v.level+`>`+v.level+`</option>`;
    
});
opt+=`</select>`;
$("#pslevel").html(opt);

},'json');



function adduser(){
    var id = $("#id").val();
    var type = $("#type").val();
    var name = $("#displayname").val();
    var account = $("#account").val();
    var password = $("#password").val();
    var jgcode = $("#jgcode").val();
    var fzr = $("#fzr").val();
    var phone  = $("#phone").val();
    var address  = $("#address").val();
    var idcard = $("#idcard").val();
    var pslevel = $("#pslevel").val();
    var company = $("#company").val();
    var description = $("#introduce").val();
    var good = $("#good").val();
    
    var isupdate = $("#isupdate").val();

    if(name == ''|| account == ''|| password == ''|| phone == ''||address == ''||idcard == ''||description == ''){
       
       console.log(name);
       console.log(account);
       console.log(password);
       console.log(phone);
       console.log(address);
       console.log(idcard);
       console.log(description);
        alert("请填写必要信息 ");
        return false;

    }

    if(type == 0 || type == 5){
          if(jgcode == ''||fzr == ''||pslevel==''){
        alert("请填写机构必要信息 ");
        return false;
        
        }


    }else{
         
        if(company==''){
        alert("请填写必要信息 ");
        return false;
        
        }

    }



    if(type ==4 || type ==5){

        if(good == ''){
        alert("请填写擅长领域必要信息，空格隔开 ");
        return false;
        
        }

    }else{

        pslevel = "非评审用户";

    }

 

    $.post("api/Admin/useradd",{"type":type,"userAccount":account,
"userPassword":password,"displayname":name,
"xydmz":jgcode,"owner":fzr,"phone":phone,"address":address,
"idnumber":idcard,"workcompany":company,"approve_level":pslevel,
"description":description,"isupdate":isupdate,"id":id,"good":good},function(res){
    if(res.result.code==200){


        alert("添加成功");
        window.location.href="/user1.html";

    }else{
        alert(res.result.msg);
    }
},'JSON');











}
</script>

<script>

function getQueryString2(name) { 
 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
 var r = window.location.search.substr(1).match(reg); 
 if (r != null) return unescape(r[2]); return null; 
} 
    var id = getQueryString2("id");

    if(id){


        $.get('api/Auth/getuser?id='+id,function(res){

            if(res.code==200){

                var user = res.result.user;
                var type = $("#type").val(user.type);

                $("#type").trigger("change");
                var name = $("#displayname").val(user.displayname);
                var account = $("#account").val(user.userAccount);
                var password = $("#password").val();
                var jgcode = $("#jgcode").val(user.xydmz);
                var fzr = $("#fzr").val(user.owner);
                var phone  = $("#phone").val(user.phone);
                var address  = $("#address").val(user.address);
                var idcard = $("#idcard").val(user.idnumber);
                var pslevel = $("#pslevel").val(user.approve_level);
                var company = $("#company").val(user.workcompany);
                var description = $("#introduce").val(user.description);
            $("#good").val(user.good);
                $("#id").val(user.id);
                $("#isupdate").val(1);



            }


        });



    }






</script>
</body>
</html>
